import axios from './init'

export interface AddRole {
  roleName:string
  roleDesc:string
}

/**
 * @function
 * */

export const getAllPermission = async () => {
  const { data } = await axios.get('rights/tree')
  return data
}

export const getAllRole = async () => {
  const { data } = await axios.get('roles')
  return data
}

export const updateRole = async (id:number, rids:Array<number>|string) => {
  rids = rids.toString()
  const { data: res } = await axios.post(`roles/${id}/rights`, { rids })
  return res
}

export const deleteOneRole = async (id:number, roleId:number) => {
  const { data: res } = await axios.delete(`roles/${id}/rights/${roleId}`)
  return res
}

export const deleteRole = async (id:number) => {
  const { data: res } = await axios.delete(`roles/${id}`)
  return res
}

export const addRole = async (data:AddRole) => {
  const { data: res } = await axios.post('roles', data)
  return res
}
